package logic

import (
	"community/api/internal/svc"
	"community/api/internal/types"
	"community/communityrpc/communityrpc"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoPostsResponseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInfoPostsResponseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoPostsResponseLogic {
	return &InfoPostsResponseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InfoPostsResponseLogic) InfoPostsResponse(req *types.InfoPostsResponseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	posts, err := l.svcCtx.CommunityRpc.InfoPosts(l.ctx, &communityrpc.InfoPostsRequest{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "详情展示成功",
		Code:    200,
		Data:    posts,
	}, nil
}
